using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using RealState.BusinessObjects;

namespace RealState.DAL
{
	public class TradeTypesDAO
	{
		public TradeTypesDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<TradeTypes> GetTradeTypess()
		{
			try
			{
				List<TradeTypes> lstTradeTypess = new List<TradeTypes>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTTradeTypess",CommandType.StoredProcedure);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					TradeTypes oTradeTypes = new TradeTypes();
                    oTradeTypes.RowNum = Convert.ToInt32(oDbDataReader["RowNum"]);
					oTradeTypes.Id = Convert.ToInt32(oDbDataReader["Id"]);
					oTradeTypes.Title = Convert.ToString(oDbDataReader["Title"]);
					lstTradeTypess.Add(oTradeTypes);
				}
				oDbDataReader.Close();
				return lstTradeTypess;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public TradeTypes GetTradeTypes(int Id)
		{
			try
			{
				TradeTypes oTradeTypes = new TradeTypes();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTTradeTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,Id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oTradeTypes.Id = Convert.ToInt32(oDbDataReader["Id"]);
					oTradeTypes.Title = Convert.ToString(oDbDataReader["Title"]);
				}
				oDbDataReader.Close();
				return oTradeTypes;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddTradeTypes(TradeTypes oTradeTypes)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERTTradeTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,oTradeTypes.Title));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateTradeTypes(TradeTypes oTradeTypes)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATETradeTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,oTradeTypes.Title));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,oTradeTypes.Id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveTradeTypes(TradeTypes oTradeTypes)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETETradeTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,oTradeTypes.Id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveTradeTypes(int Id)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETETradeTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,Id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
